package top.hkyzf.study.leetcode.math;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-3-7 10:47
 */
public class 七进制数_504 {
    public String convertToBase7(int num) {
        int surplus = num;
        StringBuilder result = new StringBuilder();
        while (surplus >= 7 || surplus <= -7) {
            int i = surplus % 7;
            result.insert(0, i < 0 ? -i : i);
            surplus = surplus / 7;
        }
        result.insert(0, surplus);
        return result.toString();
    }

    @Test
    public void testConvertToBase7 () {
        int num = -8;
        System.out.println(convertToBase7(num));
    }
}
